package webcam;

import com.github.sarxos.webcam.Webcam;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import javax.imageio.ImageIO;

/**
 *
 * @author Jens-Marius
 */
@Named(value = "camCap")
@SessionScoped
public class CamCapture implements Serializable {

    /**
     * Creates a new instance of CamCapture
     */
    
    Webcam webCam = Webcam.getDefault(); 
    public CamCapture() {
        webCam.open();
    }
    
    //a PNG in a buffer?
    public BufferedImage getImage() throws IOException{
        BufferedImage bImg = webCam.getImage();
        //Write it to database if its interessting.
        ImageIO.write(bImg, "PNG", new File("test.png"+ Math.random())); //make a local copy for fun
        return bImg;
    }
}
